<?php
namespace app\forum\controller;
use app\forum\controller\SiteController;
/**
 * 注册页面
 */
class RegController extends SiteController {

	/**
     * 注册
     */
    public function index(){
        if(!IS_POST){
            $this->crumb[] = array('url'=>url('index'),'name'=>'注册');
            $this->siteDisplay();
        }else{
            $userId = target('User')->saveData('add','username,password,email');
            if($userId){
                //设置登录
                if(target('User')->setLogin($userId)){
                    $this->redirect(url('forum/Index/index'));
                }else{
                    $this->error(target('User')->getError());
                }
            }else{
                $msg = target('User')->getError();
                if(empty($msg)){
                    $this->error('用户注册失败');
                }else{
                    $this->error($msg);
                }
            }
        }
    }

}

